using UnityEditor;
using UnityEngine;

namespace Gameplay.PVE.Editor
{
    public class RpgFlyTextEditorWindow : EditorWindow
    {
        public static RpgFlyTextEditorWindow Instance;
        
        public RpgFlyTextEditorWindow()
        {
            Instance = this;
        }
        [MenuItem("GTATools/GamePlay/PVE/RpgFlyText")]
        public static void Init()
        {
            var window = EditorWindow.GetWindow<RpgFlyTextEditorWindow>("飘字编辑器", true);
            Instance.Initialize();
        }
        
        private void Initialize()
        {
            //Instance.LoadMapData(0);
        }

        private string flyType = "0";
        private string startX;
        private string startY;
        private string endX;
        private string endY;
        private string startRandomX;
        private string startRandomY;
        private string endRandomX;
        private string endRandomY;
        private PveFlyTextConfig config;

        private void OnGUI()
        {
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("飘字类型:");
            flyType = GUILayout.TextField(flyType);
            if (GUILayout.Button("更换"))
            {
                int type;
                int.TryParse(flyType, out type);
                LoadConfig(type);
            }
            EditorGUILayout.EndHorizontal();
            
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("初始偏移X: ");
            startX = GUILayout.TextField(startX);
            GUILayout.Label("初始偏移Y: ");
            startY = GUILayout.TextField(startY);
            EditorGUILayout.EndHorizontal();
            
            EditorGUILayout.BeginHorizontal();
            GUILayout.Label("初始随机X: ");
            startRandomX = GUILayout.TextField(startRandomX);
            GUILayout.Label("初始随机Y: ");
            startRandomY = GUILayout.TextField(startRandomY);
            EditorGUILayout.EndHorizontal();
        }

        private void LoadConfig(int type)
        {
            flyType = type.ToString();
            config = PveFlyTextManager.Instance.configs[type];
            startX = config.start.x.ToString();
            startY = config.start.y.ToString();
            endX = config.end.x.ToString();
            endY = config.end.y.ToString();
            startRandomX = config.startRandom.x.ToString();
            startRandomY = config.startRandom.y.ToString();
            endRandomX = config.endRandom.x.ToString();
            endRandomY = config.endRandom.y.ToString();
        }
    }
}